
#ifndef _PARAMETER
#define _PARAMETER

#include "cv.h"
#include "highgui.h"

#include <vector>
using namespace std;

#define NUM_X 1
#define NUM_Y 1
#define NUM_Z 3

#define HUE_FLAG 400

typedef struct info 
{
	int num;					//number 
	double *vol;					//volume
	int loc[NUM_X][NUM_Y][NUM_Z];		//distribution
} Info;

void Unify(IplImage *image, int sel);

void otsu(IplImage* A, IplImage* B, int sel);

void thre(IplImage* A, IplImage* B, int sel);

void thre(IplImage* A, IplImage* B, int sel, int th);

void filter(IplImage* A, int sel);

void RetrieveInfo(IplImage *cur, IplImage *pre, int sel, int plane, Info &inf, int &start, double DEPTH_RATIO);

void Contain(IplImage *fill, int sel1, IplImage *container, int sel2);

void Overlap(IplImage *fill, int sel1, IplImage *container, int sel2);

float fGetParaValue(CString InPathStr, CString pInstr);

float fGetParaValue(CString InPathStr, CString pInstr1, CString pInstr2);

char* fGetParaString(CString InPathStr, CString pInstr);

int iGetBandwidth(CString InPathStr, CString pInstr);


//////////////////////////////////////////////////////////////////////////
void * fspace_1d(int col, int length);

void ffree_1d(void *a);

void ** fspace_2d(int row,int col,int lenth);

void ffree_2d(void **a,int row);

void ***fspace_3d(int row1,int row2,int row3,int lenth);

void ffree_3d(void ***a,int row1,int row2);

void ****fspace_4d(int row1,int row2,int row3,int row4, int lenth);

void ffree_4d(void ****a,int row1,int row2, int row3);


//////////////////////////////////////////////////////////////////////////

void KMeans(IplImage *pInImage ,int sel, int iClusterCount);

void iteration(float *pfClusterCenter, int *piSrcImage, int *piLabel, int ilength, int iClusterCount, int *iflag);

int WriteAsBmp(unsigned char *image , int row , int col, char *fileName, int nMode);

void RGBtoHSV(float r, float g, float b, float *h, float *s, float *v);

void RGBtoHSI(float r, float g, float b, float *h, float *s, float *v);

void HSVtoRGB(int *r, int *g, int *b, float h, float s, float v);



int GetMedValue(unsigned char * bArray, int iFilterLen);

void Medianfilter (IplImage* A, IplImage* B, int sel, int FilterWH);

void Medianfilter(BYTE *pInImage, BYTE *pOutImage, int iFilterH, int iFilterW, int iImageH, int iImageW);


//////////////////////////////////////////////////////////////////////////
#define LABELMODE_1  1
#define LABELMODE_2  2

#define ERROR        -1

//#define MAXSLINK     256   /* 0 --- 255  */
//#define MAXLINK      1024  /* 0 --- 1023 */
//#define MAXSUBBLOCK  1023  /* 1 --- 1023 */
//#define MAXBLOCK     255   /* 1 --- 255  */
//#define MAXGREYLEVEL 255   /* 0 --- 255  */

#define MAXSLINK     256   /* 0 --- 255  */
#define MAXLINK      1024  /* 0 --- 1023 */
#define MAXSUBBLOCK  1023  /* 1 --- 1023 */
#define MAXBLOCK     255   /* 1 --- 255  */
#define MAXGREYLEVEL 255   /* 0 --- 255  */

#define NEIGHBORDATATYPE unsigned short
#define TmpAreaDATATYPE unsigned short
#define LABELDATATYPE unsigned char

NEIGHBORDATATYPE GetNeighborTable(LABELDATATYPE *array, int RowLen, int ColLen,
								  NEIGHBORDATATYPE neighbor[2*MAXLINK], NEIGHBORDATATYPE *TemArray,
								  unsigned *TabLen, TmpAreaDATATYPE area[MAXSUBBLOCK+1]);	
unsigned GetMapTable(NEIGHBORDATATYPE neighbor[2*MAXLINK], unsigned TabLen,
					 NEIGHBORDATATYPE map[MAXSUBBLOCK+1]);
int ModifyMapTable1(NEIGHBORDATATYPE map[MAXSUBBLOCK+1], TmpAreaDATATYPE area[MAXSUBBLOCK+1], NEIGHBORDATATYPE GrayNo,
					unsigned TrueObj, int MinArea);
void ModifyMapTable2(NEIGHBORDATATYPE map[MAXSUBBLOCK+1], TmpAreaDATATYPE area[MAXSUBBLOCK+1], NEIGHBORDATATYPE GrayNo,
					 unsigned TrueObj);

void DoMap(LABELDATATYPE *array,NEIGHBORDATATYPE *TemArray,  int RowLen,  int ColLen,
		   NEIGHBORDATATYPE map[MAXSUBBLOCK+1], int maxgraylevel);

int Label(LABELDATATYPE *array, int RowLen,  int ColLen, int LabelMode,  
		  int MinArea, int maxgraylevel);


//////////////////////////////////////////////////////////////////////////
void OtsuSegment(BYTE **SourceImg, int SRow, int SCol, BYTE **OutImg);

BYTE *Trans2To1( BYTE ** p, int row, int col);
BYTE ** Trans1To2( BYTE * p, int row, int col);

//////////////////////////////////////////////////////////////////////////


float MinDistance(float *fHValue, float H, int iNum);

//////////////////////////////////////////////////////////////////////////

int *** ImageCombine(int ***ImageSrc1, int***ImageSrc2, 
					 int num_plane, int iHeight, int iWidth);



int *** ImageCombine(int ***ImageSrc1, int***ImageSrc2, 
					 int ***ImageSrc3, int num_plane, int iHeight, int iWidth);


int *** ImageCombine(int ***ImageSrc1, int***ImageSrc2,
					 int ***ImageSrc3,int ***ImageSrc4, 
					 int num_plane, int iHeight, int iWidth);



int *** ImageCombine(int ***ImageSrc1, int***ImageSrc2, 
					 int ***ImageSrc3, int***ImageSrc4, 
					 int ***ImageSrc5, 
					 int num_plane, int iHeight, int iWidth);



#endif